package com.ads.proplan.activity;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.Html;
import android.widget.Button;
import android.widget.Toast;

import com.ads.proplan.R;
import com.ads.proplan.db.SessaoPerguntaRepository;
import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_configuracao)
public class ConfiguracaoActivity extends Activity{
	public static final String TAG_SOM = "SOM";
	private boolean som;
	private SharedPreferences prefs;
	private SessaoPerguntaRepository sessaoPerguntaRepos;
	
	@ViewById(R.id.configuracao_button_son)
	public Button somButton;
	@ViewById(R.id.configuracao_button_musica)
	public Button musicaButton;
	@ViewById(R.id.configuracao_button_dificudade)
	public Button dificuldadeButton;
	@ViewById(R.id.configuracao_button_reiniciar)
	public Button limparButton;
	
	@Override
	protected void onStart() {
		super.onStart();
		somChecked();
	}
	
	@Click(R.id.configuracao_button_son)
	public void onClickSom(){
		if(som){
			prefs.edit().putBoolean(TAG_SOM, false).commit();
			som = false;
			somButton.setText(Html.fromHtml(getString(R.string.son_of)));
		}else{
			prefs.edit().putBoolean(TAG_SOM, true).commit();
			som = true;
			somButton.setText(Html.fromHtml(getString(R.string.son_on)));
		}
	}
	
	@Click(R.id.configuracao_button_musica)
	public void onClickMusica(){
		Toast.makeText(getApplicationContext(),("onClickMusica"), Toast.LENGTH_SHORT).show();
	}
	
	@Click(R.id.configuracao_button_dificudade)
	public void onClickDificuldade(){
		Toast.makeText(getApplicationContext(),("onClickDificuldade"), Toast.LENGTH_SHORT).show();
	}
	
	@Click(R.id.configuracao_button_reiniciar)
	public void onClickLimpar(){
		if (sessaoPerguntaRepos == null) 
			sessaoPerguntaRepos = new SessaoPerguntaRepository(this);
		sessaoPerguntaRepos.dropTable();
		Toast.makeText(getApplicationContext(),("Perguntas responidas apagadas"), Toast.LENGTH_LONG).show();
	}
	
	private void somChecked() {
		if (prefs == null) {
			prefs = this.getSharedPreferences(QuestionActivity.TAG_SharedP, Context.MODE_PRIVATE);
		}
		som = prefs.getBoolean(TAG_SOM, true);
		if(som){
			somButton.setText(Html.fromHtml(getString(R.string.son_on)));
		}else{
			somButton.setText(Html.fromHtml(getString(R.string.son_of)));
		}
	}
}
